<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <h1>JS内置对象 - RegExp</h1>
    <hr>

    <script>
    var str = 'I am abc 12345';
    var reg = /^\w{5}$/;

    var reg = new RegExp(/\d{2}/);

    console.log(reg);
    console.log(typeof(reg));
    console.log(reg.constructor);

    // test(str) 匹配返回true,不匹配返回false
    console.log(reg.test(str));
    console.log(/\w{99}/.test(str));

    // exec(str) 匹配文本,成功返回数组对象,失败返回null
    console.log(/\d{5}/.exec(str));
    console.log(/\d{56}/.exec(str));

    var a = /\d{5}/.exec(str);
    if (a !== null) {
        // console.log(a[0]);
        console.log(a.index);
    }
    
    </script>

</body>
</html>